package com.itheima.controller.clazzInfo;

import com.itheima.domin.pojo.Student;
import com.itheima.domin.query.StudentQuery;
import com.itheima.domin.vo.Result;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**学生控制
 * @Author:上官徵羽
 * @Date: 2025/07/11 20:47
 * @Description TODO 今日内容:
 */
@RestController
@Slf4j
@RequestMapping(value = "/students")
public class StudentController {
    @Autowired
    private StudentService studentService;


    /**
     * 违纪扣分模块
     * @param score
     * @return
     */
    @PutMapping("/violation/{id}/{score}")
    public Result disciplinaryDisposition(@PathVariable("score") Integer score,@PathVariable("id") Integer id ){
        studentService.disciplinaryDisposition(score,id);
        return Result.success();
    }

    /**
     * 修改学员信息模块
     * @param student
     * @return
     */
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

    /**
     * 根据ID查询学生(数据回显)
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectStudentId(@PathVariable Integer id){
        return Result.success(studentService.selectStudentId(id));
    }

    /**
     * 添加学生模块
     * @param student
     * @return
     */
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }
    /**
     * 学生批量删除模块
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result deleteStudentIds(@PathVariable Integer[] ids){
        log.info("StudentController deleteStudentIds:{}", Arrays.toString(ids));
        studentService.deleteStudentIds(ids);
        return Result.success();
    }

    /**
     * 学员列表分页查询
     * @param studentQuery
     * @return
     */
    @GetMapping
    public Result findAll(StudentQuery studentQuery){
        log.info("StudentController findAll");
        return Result.success(studentService.findAll(studentQuery));
    }
}
